/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.fehler;

import java.lang.reflect.Array;

import de.mnit.basis.fehler.system.F_Array;

/**
 * @author Michael Nitsche
 */
public class H_Array {

	public static F_Array debugFehler(Object... o)  		{ return F_Array.neu(Fehler.text_debug, o); }

	public static F_Array da_ElementFehlt(Object... o)	{ return F_Array.neu("Element fehlt",o); }


	public static void wenn_ZuKurz(int min, Object o) {
		int laenge=0;
		try {
			laenge=Array.getLength(o);
		}
		catch(IllegalArgumentException e)   { Fehler.objekt.da_KlasseUngueltig(o); }
		if(laenge<min) F_Array.neu("Array ist zu kurz","Länge: "+laenge,"Min: "+min);
	}

	public static void wenn_ElementNull(Object[] oa) {
		Fehler.objekt.wenn_Null(oa);
		for(int i=0; i<oa.length; i++)
			if(oa[i]==null) F_Array.neu("Element ist null im Array", "Nr: "+(i+1), oa);
	}

	/** FIXME Hier stimmt doch was nicht!?!? **/
	public static void wenn_ElementklasseFalsch(Object[] oa, Class<?>... gueltig) {
		for(Object o : oa) {
			Class<?> c=o.getClass();
//			o instanceof Class ? (Class<?>)ist :

			for(Class<?> g : gueltig)
//				if(c.equals(e)) treffer=true;
//				if(e.isInstance(c)) treffer=true;
				if(g.isAssignableFrom(c))
					return;
		}
	}

}
